package com.hq.controller;


import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.hq.bean.AmountByMarkAge;
import com.hq.bean.AmountByMarkGender;
import com.hq.bean.MarkProvince;
import com.hq.service.AmountByProvinceService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class AmountByMark {

    @Resource
    private AmountByProvinceService amountByProvinceService;


    // 品牌性别
    @RequestMapping("/listByMarkGender")
    public Object amountByMarkGender(){
        List<AmountByMarkGender> amountByMarkGenders = amountByProvinceService.listAmountByMarkGender();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject jsonObject1 = new JSONObject();
        JSONArray jsonArray1 = new JSONArray();
        //3个小的json对象
        JSONObject l1 = new JSONObject();
        l1.put("name","品牌");
        l1.put("id","tm_name");
        JSONObject l2 = new JSONObject();
        l2.put("name","性别");
        l2.put("id","gender");
        JSONObject l3 = new JSONObject();
        l3.put("name","总金额");
        l3.put("id","total");
        jsonArray1.add(l1);
        jsonArray1.add(l2);
        jsonArray1.add(l3);
        jsonObject1.put("columns",jsonArray1);

        JSONArray jsonArray2 = new JSONArray();
        for (AmountByMarkGender amountByMarkGender : amountByMarkGenders) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("tm_name",amountByMarkGender.getTm_name());
            jsonObject2.put("gender",amountByMarkGender.getGender().equals("M")?"男":"女");
            jsonObject2.put("total",amountByMarkGender.getTotal());
            jsonArray2.add(jsonObject2);
        }
        jsonObject1.put("rows",jsonArray2);

        jsonObject.put("data",jsonObject1);


        return jsonObject;
    }

    // 品牌省份\
    @RequestMapping("/listByMarkProvince")
    public Object amountByMarkProvince(){
        List<MarkProvince> markProvinces = amountByProvinceService.listAmountByMarkProvince();
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        JSONObject jsonObject1 = new JSONObject();
        JSONArray jsonArray1 = new JSONArray();
        //3个小的json对象
        JSONObject l1 = new JSONObject();
        l1.put("name","品牌");
        l1.put("id","tm_name");
        JSONObject l2 = new JSONObject();
        l2.put("name","省份");
        l2.put("id","name");
        JSONObject l3 = new JSONObject();
        l3.put("name","总金额");
        l3.put("id","total");
        jsonArray1.add(l1);
        jsonArray1.add(l2);
        jsonArray1.add(l3);
        jsonObject1.put("columns",jsonArray1);

        JSONArray jsonArray2 = new JSONArray();
        for (MarkProvince markProvince : markProvinces) {
            JSONObject jsonObject2 = new JSONObject();
            jsonObject2.put("tm_name",markProvince.getTm_name());
            jsonObject2.put("name",markProvince.getName());
            jsonObject2.put("total",markProvince.getTotal());
            jsonArray2.add(jsonObject2);
        }
        jsonObject1.put("rows",jsonArray2);
        jsonObject.put("data",jsonObject1);
        return jsonObject;
    }
}
